package com.hg.library.ui.gallery;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;

import com.hg.library.utils.AnimUtils;

/**
 * Created by wangjianqiang on 2016/4/22.
 */
public class LabelGallery extends Gallery {

    private View currentView;

    public LabelGallery(Context context) {
        super(context);
        init();
    }

    public LabelGallery(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public LabelGallery(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
//        setOnItemSelectedListener(new MyOnItemSelectedListener());
    }

    class MyOnItemSelectedListener implements OnItemSelectedListener {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            int resouceID = (int)getAdapter().getItem(position);
            if (hasFocus()) {
                if (currentView != null) {
                    AnimUtils.scaleAnimY(currentView, 500, 1.5f, 1.0f);
                }
                AnimUtils.scaleAnimY(view, 500, 1.0f, 1.5f);
            }
            currentView = view;
            View view0 = getChildAt(0);
            View view1 = getChildAt(1);
            View view2 = getChildAt(2);
            View view3 = getChildAt(3);
            view0.setAlpha(0.6f);
            view1.setAlpha(0.6f);
            view2.setAlpha(0.6f);
            if(view3 != null){
                view3.setAlpha(0.6f);
            }
            view.setAlpha(1);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    }
}
